// pages/promise/item/item.js
const choiceIconList = {
  common: 'chevron-right',
  unChecked: 'circle',
  checked: 'check-circle-filled'
}

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    isdelete: {
      type: Boolean,
      value: false
    },
    companyInfo: {
      type: Object,
      value: []
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    selectedList:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    tapCard(event) {
      if (this.data.isdelete) {
        this.selectCard(event.currentTarget.dataset.index)
        this.getCardsData()
      } else {
        this.gotoConpanyDetail(this.getIdFromTagId(event.currentTarget.id))
      }
    },
    gotoConpanyDetail(id) {
      wx: wx.navigateTo({
        url: `/pages/companyInformation/companyDetails/companyDetails?id=` + id,
        events: false,
        success: (result) => { },
        fail: (res) => { },
        complete: (res) => { },
      })
    },
    selectCard(tagId) {
        this.setData({
          [`companyInfo[${tagId}]`]:typeof(this.data.companyInfo[tagId].isSelected)==='boolean'?{...this.data.companyInfo[tagId],isSelected:!this.data.companyInfo[tagId].isSelected}:{isSelected:true,...this.data.companyInfo[tagId]}
        })
    },
    /**
     * @public 自定义事件，由companyInfomation触发
     */
    getCardsData(){
      this.triggerEvent('getCardsData',this.data.companyInfo)
    },
    /*
   *通用函数
  */
    getIdFromTagId(result) {
      return result.match(/\d+$/)[0]
    },
  },
})
